package page.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javabean.UserInfo;
import table.UserInfoTable;
import util.Constant;
import util.PubFun;
import page.inc.HtmlPage;

public class EditUserInfoPage extends HtmlPage {

	public String print(HttpServletRequest req, HttpServletResponse resp)
			throws Exception {
		UserInfo user = getSessionUser(req);
		if (user == null) {
			resp.sendRedirect(Constant.REDIRECT_LOGIN_PAGE);
			return null;
		}
		/** ****************添加用户信息**************** **/
		int userID = getIntParameter("user_id", 0, req);
		if(userID == 0 || !UserInfoTable.isExistsUserById(userID)){
			PubFun.ajaxPrintStr("此用户不存在。", resp);
			return null;
		}
		int depId = getIntParameter("dep_id", 0, req);
		if(depId == 0){
			PubFun.ajaxPrintStr("请选择所属部门。", resp);
			return null;
		}	
		UserInfo userInfo = new UserInfo();
		userInfo.setId(userID);
		userInfo.setAlias(getStringParameter("alias", "", req));
		userInfo.setDepId(depId);
		userInfo.setArticleRole(getBooleanParameter("is_article", false, req));
		userInfo.setAdRole(getBooleanParameter("is_ad", false, req));
		userInfo.setPublishRole(getBooleanParameter("is_publish", false, req));
		userInfo.setColumnRole(getBooleanParameter("is_column", false, req));

		UserInfoTable.updateUserInfo(userInfo);
		return "/MainCtrl?page=UserManagePage";
	}

}
